home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v16n10 / embedcp.exe / CODE.EXE / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-28  |  5.0 KB  |  183 lines

  1. // MIOTDREM
  2. // --------
  3. //
  4. // Copyright (c) 1991, Stuart G. Phillips.  All rights reserved.
  5. //
  6. // Permission is granted for non-commercial use of this software.
  7. // You are expressly prohibited from selling this software in any form,
  8. // distributing it with another product, or removing this notice.
  9. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  10. // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  11. // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. // PURPOSE.
  13. //
  14. // This module contains the main() for the MIO version of TDREMOTE.  The
  15. // module is primarily responsible for initialization; TDREMOTE functions
  16. // are handled in other modules.
  17. //
  18. //
  19.  
  20.  
  21. #include "mio.h"
  22. #include "8530.h"
  23. #include "miotdr.h"
  24.  
  25. #ifdef SERIAL_DEBUG
  26.  
  27. // Communication region used to deposit status information about the
  28. // programs progress etc in the shared memory window.
  29. //
  30.  
  31. struct comm_region {    unsigned short status;
  32.                         unsigned short scc_status;
  33.                         unsigned short scc_special;
  34.                         unsigned short int_cnt;
  35.                         unsigned short rx_cnt;
  36.                         unsigned short tx_cnt;
  37.                         unsigned char  command;
  38.                    };
  39. #endif
  40.  
  41. struct relo_creg {      unsigned short offset;
  42.                         unsigned short segment;
  43.                         unsigned short count;
  44.                         unsigned char command;
  45.                  };
  46.  
  47. // Command values for RELO.LOD
  48.  
  49. #define RELO_NULL       0x00
  50. #define RELO_COPYTO     0x01
  51. #define RELO_COPYFROM   0x02
  52. #define RELO_EXIT       0x03
  53.  
  54. // Magic number signifying presence of "RELO" support
  55.  
  56. #define RELO_MAGIC      0x5a41
  57.  
  58.  
  59. extern void tdr_processor();
  60.  
  61. static void relo_lod();
  62.  
  63. #ifdef SERIAL_DEBUG
  64. static struct comm_region *creg = (struct comm_region *)0x80;
  65. #endif
  66.  
  67. // Globals
  68.  
  69. unsigned char rx_buffer[BUFLEN],
  70.               tx_buffer[BUFLEN];
  71.  
  72. unsigned _stklen = 512U;
  73.  
  74. void main()
  75. {
  76.     unsigned char data,val;
  77.     unsigned short i;
  78.  
  79.     disable();
  80.  
  81.     // Enable ICU in the V40 peripheral select register
  82.  
  83.     data = inportb(OPSEL);
  84.     outportb(OPSEL,data|ICU);
  85.     data = inportb(OPSEL);
  86.  
  87. #ifdef SERIAL_DEBUG
  88.     creg->status = data;
  89. #endif
  90.  
  91.     /* Initialize the ICU */
  92.  
  93.     outportb(IULA,ICUBASE);                     // set base address */
  94.     outportb(IMDW,IIW1|IIW4NR|IEM|IET);         // no IIW4, extended mode,
  95.                                                 // edge triggered
  96.                                                 //
  97.     outportb(IMKW,IVEC);                        // Set vector base for PIC/
  98.     outportb(IMKW,SI7);                         // IRQ7 is slave
  99.  
  100.     outportb(IMKW,0xff);                        // Mask off all interrupts
  101.  
  102.     relo_lod();                                 // Provide relocation support
  103.                                                 // to MIOLOAD
  104. #ifdef SERIAL_DEBUG
  105.     creg->status = 0;
  106.     creg->scc_status = 0;
  107.     creg->scc_special = 0;
  108.     creg->int_cnt = 0;
  109.     creg->rx_cnt = 0;
  110.     creg->tx_cnt = 0;
  111.     creg->command = 0xff;
  112. #endif
  113.  
  114.     comm_init();
  115.  
  116.     tdr_processor();
  117.     /*NOTREACHED*/
  118. }
  119.  
  120.  
  121. static void relo_lod()
  122. {
  123.  
  124.     struct relo_creg *creg = (struct relo_creg *) 0x80;
  125.     unsigned short *magic = (unsigned short *) 0x88;
  126.     unsigned char *go = (unsigned char *) 0x9f;
  127.     unsigned char *swin, *p;
  128.     unsigned short i, relo_done = 0;
  129.  
  130.     // Initialize command field in communication region
  131.  
  132.     creg->command = 0xff;
  133.  
  134.     // Implant magic number so that MIOLOAD knows we're up and running
  135.  
  136.     *magic = RELO_MAGIC;
  137.  
  138.     while (!relo_done){
  139.         // Wait for command value to change from 0xff
  140.         while (creg->command == 0xff) ;
  141.  
  142.         switch(creg->command){
  143.             case RELO_COPYTO:
  144.                 p = (unsigned char *)(((long)creg->segment << 16) +
  145.                                        (long)creg->offset);
  146.                 swin = (unsigned char *) 0x100;
  147.  
  148.                 for(i = creg->count; i != 0; i--)
  149.                     *p++ = *swin++;
  150.                 creg->command = 0xff;
  151.                 break;
  152.  
  153.             case RELO_COPYFROM:
  154.                 p = (unsigned char *)(((long)creg->segment << 16) +
  155.                                        (long)creg->offset);
  156.                 swin = (unsigned char *) 0x100;
  157.  
  158.                 for(i = creg->count; i != 0; i--)
  159.                     *swin++ = *p++;
  160.                 creg->command = 0xff;
  161.                 break;
  162.  
  163.             case RELO_EXIT:
  164.                 creg->command = 0xff;
  165.                 relo_done = 1;
  166.                 break;
  167.  
  168.             default:
  169.                 creg->command = 0xff;
  170.                 break;
  171.         }
  172.     }
  173.  
  174.     // Clear our magic marker and then reset the go flag to the 0xf4
  175.     // (halt) code.  Wait for MIOLOAD to set this to 0x90 to indicate
  176.     // we should continue.
  177.  
  178.     *magic = 0;
  179.     *go = 0xf4;
  180.  
  181.     while (*go != 0x90) ;
  182. }
  183.